import React from 'react';
import ReactEcharts from 'echarts-for-react';
import jQuery from "jquery";

const globalConfig = require("../../js/globalConfig");
const utils = require("../../js/utils");

const titles = ["电机", "卷筒左轴承座", "卷筒右轴承座", "导向轮"];
const colors = ['#5470c6', '#91cc75', '#fac858', '#ee6666']

class TodayVib extends React.Component{
    constructor(props) {
        super(props);

        this.state = {
            url: this.props.flag ? globalConfig.url + "/getMainTodayVib" : globalConfig.url + "/getSubTodayVib",
            option: {
                title: {
                    text: titles[this.props.num],
                    left: "center",
                    textStyle: {
                        fontSize: 16,
                        fontWeight: "normal"
                    }
                },
                tooltip: {},
                calculable: true,
                xAxis: [
                    {
                        type: 'category',
                        name: "小时(h)",
                    }
                ],
                yAxis: [
                    {
                        name: "振动(μm)",
                        type: 'value',
                    }
                ],
                series: [
                    {
                        symbol: 'circle',
                        name: titles[this.props.num],
                        type: "line",
                        itemStyle: {
                            normal: {
                                color: colors[this.props.num],
                                lineStyle: {
                                    color: colors[this.props.num]
                                }
                            }
                        },
                    }
                ],
                grid: {
                    top: 50,
                    left: 45,
                    right: 45,
                    bottom: 25
                }
            },
        }
    }
    componentDidMount(){
        const instance = this.echartsReact.getEchartsInstance();
        var this_ = this;
        jQuery.ajax({
            url: this_.state.url,
            dataType: "JSON",
            type: "POST",
            data: {},
            success: function (result) {
            }
        });
    }
    render(){
        return(<ReactEcharts ref={e => { this.echartsReact = e; }} option={this.state.option} style={{ height: "100%", width: "100%" }} opts={{ renderer: 'svg' }} />);
    }
}

export default TodayVib;